package com.zyit.controller;

import com.zyit.model.Patient;
import com.zyit.service.PatientService;
import com.zyit.util.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/patients")
public class PatientController {


    @Resource
    private PatientService patientService;


    @PostMapping("add")
    public Result add(Patient patient) {
        int i1 = patientService.findByIdCard(patient.getIdCard()) + patientService.findByIdMedicare(patient.getIdMedicare());
        if (i1 > 0) {
            return new Result(0, null, "添加失败");
        }
        int i = patientService.add(patient);
        return new Result(i, null, "");
    }

    @DeleteMapping
    public Result del(String id) {
        int i = patientService.del(id);
        System.out.println(i);
        Result result = new Result(i, null, "");
        return result;
    }

    @GetMapping("/findByIdCard")
    public Result findByIdCard(String idCard) {
        int i = patientService.findByIdCard(idCard);
        return new Result(200, i, "");
    }

    @GetMapping("/findByIdMedicare")
    public Result findByIdMedicare(String idMedicare) {
        int i = patientService.findByIdMedicare(idMedicare);
        return new Result(200, i, "");
    }
    @GetMapping("/findByIdCardReturn")
    public Result findByIdCardReturn(String idMedicare) {
        return new Result(200, patientService.findByIdCardReturn(idMedicare), "");
    }


}
